﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Media.Imaging;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409

namespace CODWXEDU
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public static string dt = "UTC: " + DateTime.UtcNow.ToString("MM/dd/yyyy HH:mm") + 
            "\nLocal: " + DateTime.Now.ToString("MM/dd/yyyy HH:mm");

        
        public MainPage()
        {
            
            this.InitializeComponent();
            textBlock.Text = dt;


        }

        private void comboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }

        private void button_Click(object sender, RoutedEventArgs e)
        {
            string dt = "UTC: " + DateTime.UtcNow.ToString("MM/dd/yyyy HH:mm") +
            "\nLocal: " + DateTime.Now.ToString("MM/dd/yyyy HH:mm");
            textBlock.Text = dt;
            //2m temp
            if (comboBox.SelectedIndex == 0)
            {
                string offset = (string)comboBox2.SelectedItem.ToString().TrimStart('+').PadLeft(3,'0');
                string model_run = (string)comboBox1.SelectedItem.ToString().TrimEnd('z').PadLeft(2,'0');
                string uri1 = "http://climate.cod.edu/data/forecast/NAM/" + model_run + "/US/namUS_sfc_temp_" + offset + ".gif";
                Debug.WriteLine(uri1);
                BitmapImage bi3 = new BitmapImage();
                bi3.UriSource = new Uri(uri1, UriKind.Absolute);
                image.Source = bi3;
            }

            //2m theta-e
            if (comboBox.SelectedIndex == 1)
            {
                string offset = (string)comboBox2.SelectedItem.ToString().TrimStart('+').PadLeft(3, '0');
                string model_run = (string)comboBox1.SelectedItem.ToString().TrimEnd('z').PadLeft(2, '0');
                string uri1 = "http://climate.cod.edu/data/forecast/NAM/" + model_run + "/US/namUS_sfc_thetae_" + offset + ".gif";
                Debug.WriteLine(uri1);
                BitmapImage bi3 = new BitmapImage();
                bi3.UriSource = new Uri(uri1, UriKind.Absolute);
                image.Source = bi3;
            }
            //2m Moisture Advection
            if (comboBox.SelectedIndex == 2)
            {
                string offset = (string)comboBox2.SelectedItem.ToString().TrimStart('+').PadLeft(3, '0');
                string model_run = (string)comboBox1.SelectedItem.ToString().TrimEnd('z').PadLeft(2, '0');
                string uri1 = "http://climate.cod.edu/data/forecast/NAM/" + model_run + "/US/namUS_sfc_30mbdewp_" + offset + ".gif";
                Debug.WriteLine(uri1);
                BitmapImage bi3 = new BitmapImage();
                bi3.UriSource = new Uri(uri1, UriKind.Absolute);
                image.Source = bi3;
            }
            //SigTor param
            if (comboBox.SelectedIndex == 3)
            {
                string offset = (string)comboBox2.SelectedItem.ToString().TrimStart('+').PadLeft(3, '0');
                string model_run = (string)comboBox1.SelectedItem.ToString().TrimEnd('z').PadLeft(2, '0');
                string uri1 = "http://climate.cod.edu/data/forecast/NAM/" + model_run + "/US/namUS_con_stp_" + offset + ".gif";
                Debug.WriteLine(uri1);
                BitmapImage bi3 = new BitmapImage();
                bi3.UriSource = new Uri(uri1, UriKind.Absolute);
                image.Source = bi3;
            }
            //Supercell composite param
            if (comboBox.SelectedIndex == 4)
            {
                string offset = (string)comboBox2.SelectedItem.ToString().TrimStart('+').PadLeft(3, '0');
                string model_run = (string)comboBox1.SelectedItem.ToString().TrimEnd('z').PadLeft(2, '0');
                string uri1 = "http://climate.cod.edu/data/forecast/NAM/" + model_run + "/US/namUS_con_scp_" + offset + ".gif";
                Debug.WriteLine(uri1);
                BitmapImage bi3 = new BitmapImage();
                bi3.UriSource = new Uri(uri1, UriKind.Absolute);
                image.Source = bi3;
            }
            // Precip Accumulation
            if (comboBox.SelectedIndex == 5)
            {
                string offset = (string)comboBox2.SelectedItem.ToString().TrimStart('+').PadLeft(3, '0');
                string model_run = (string)comboBox1.SelectedItem.ToString().TrimEnd('z').PadLeft(2, '0');
                string uri1 = "http://climate.cod.edu/data/forecast/NAM/" + model_run + "/US/namUS_prec_precacc_" + offset + ".gif";
                Debug.WriteLine(uri1);
                BitmapImage bi3 = new BitmapImage();
                bi3.UriSource = new Uri(uri1, UriKind.Absolute);
                image.Source = bi3;
            }
            // GFS 2m temp
            if (comboBox.SelectedIndex == 6)
            {
                string offset = (string)comboBox2.SelectedItem.ToString().TrimStart('+').PadLeft(3, '0');
                string model_run = (string)comboBox1.SelectedItem.ToString().TrimEnd('z').PadLeft(2, '0');
                string uri1 = "http://climate.cod.edu/data/forecast/GFS/" + model_run + "/US/gfsUS_sfc_temp_" + offset + ".gif";
                Debug.WriteLine(uri1);
                BitmapImage bi3 = new BitmapImage();
                bi3.UriSource = new Uri(uri1, UriKind.Absolute);
                image.Source = bi3;
            }
          


    }
    }
}
